package com.wsk.read;

import java.io.*;
import java.util.ArrayList;

/**
 * Created by Maibenben on 2017/1/4.
 */
public class ReadTxt {
    public static ArrayList readTxt() throws IOException {
        ArrayList<String> list = new ArrayList<>();
        String encoding = "GBK";
        File file = new File("txt\\all.txt");
//        File file = new File("C:\\Users\\Administrator\\Workspaces\\MyEclipse 2016 CI\\movie\\txt\\all.txt");
        InputStreamReader reader = new InputStreamReader(new FileInputStream(file), encoding);
        BufferedReader bufferedReader = new BufferedReader(reader);
        String txt=null;
        while ((txt=bufferedReader.readLine())!=null){
            list.add(txt);
        }
        reader.close();
        return list;
    }
    public static ArrayList readTxt2() throws IOException {
        ArrayList<String> list = new ArrayList<>();
        String encoding = "GBK";
        File file = new File("txt\\cc2.txt");
//        File file = new File("C:\\Users\\Administrator\\Workspaces\\MyEclipse 2016 CI\\movie\\txt\\all.txt");
        InputStreamReader reader = new InputStreamReader(new FileInputStream(file), encoding);
        BufferedReader bufferedReader = new BufferedReader(reader);
        String txt=null;
        while ((txt=bufferedReader.readLine())!=null){
            list.add(txt);
        }
        reader.close();
        return list;
    }

    public static String txtReplace(String test){
            try {
                ArrayList<String> list=readTxt();
                test=test.replaceAll("\\s*", "");
                for (String aList : list) {
                    test = test.replaceAll(aList, "**");
                }
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        return test;
    }
    public static void main(String[] args){
        double start=System.currentTimeMillis();
        String test="哟，   六合 采真是个  好东西,一    氧化二氟,谢育峰是个大 S B,钓 鱼 岛";
        test = txtReplace(test);
//            ArrayList<String> list=readTxt();
//            test = test.replaceAll("\\s*", "");
//            System.out.println("原文:："+test);
//            for (int i=0;i<list.size();i++){
//                String cc = list.get(i);
//                test=test.replaceAll(cc,"**");
//            }
        double end=System.currentTimeMillis();
        double between=end-start;
        System.out.println(test);
        System.out.println(between+"ms");
    }
}
